package com.sinosoft.bee.services.proposal.mapper;

import com.sinosoft.bee.services.proposal.entity.proposal.ProposalAppnt;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: TrickerL
 * @Description: bee
 * @Date: Create in 15:06 2018/5/16
 * @Modified By:
 */
@Mapper
@Repository
public interface AppntInfoMapper {

    /**
     *向投保人表中插入投保人信息
     * @param appnt
     * @return
     */
    @Insert("INSERT INTO proposal_appnt (\n" +
            "  proposal_id,\n" +
            "  appnt_id,\n" +
            "  NAME,\n" +
            "  sex,\n" +
            "  birthday,\n" +
            "  age,\n" +
            "  occupation_code,\n" +
            "  occupation_type,\n" +
            "  is_social_insu,\n" +
            "  create_user,\n" +
            "  gmt_create,\n" +
            "  modified_user,\n" +
            "  gmt_modified,\n" +
            "  is_deleted\n" +
            ")\n" +
            "VALUES\n" +
            "  (\n" +
            "    #{proposalId},\n" +
            "    #{appntId},\n" +
            "    #{name},\n" +
            "    #{sex},\n" +
            "    #{birthday},\n" +
            "    #{age},\n" +
            "    #{occupationCode},\n" +
            "    #{occupationType},\n" +
            "    #{isSocialInsu},\n" +
            "    #{createUser},\n" +
            "    #{gmtCreate},\n" +
            "    #{modifiedUser},\n" +
            "    #{gmtModified},\n" +
            "    #{isDeleted}\n" +
            "  );")
    Integer insertAppntInfo(ProposalAppnt appnt);

    /**
     * 根据投保人ID删除投保人
     * @param appnt
     * @return
     */
    @Delete("delete from proposal_appnt where appnt_id=#{appntId};")
    Integer deleteAppntInfo(ProposalAppnt appnt);

    /**
     * 通过建议书号查询投保人
     * @param appntId
     * @return
     */
    @Results(id = "appnt", value = {
            @Result(property = "proposalId", column = "proposal_id"),
            @Result(property = "appntId", column = "appnt_id"),
            @Result(property = "name", column = "name"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "age", column = "age"),
            @Result(property = "occupationCode", column = "occupation_code"),
            @Result(property = "occupationType", column = "occupation_type"),
            @Result(property = "isSocialInsu",column = "is_social_insu"),
            @Result(property = "createUser", column = "create_user"),
            @Result(property = "gmtCreate", column = "gmt_create"),
            @Result(property = "modifiedUser", column = "modified_user"),
            @Result(property = "gmtModified", column = "gmt_modified"),
            @Result(property = "isDeleted", column = "is_deleted")
    })
    @Select("select * from proposal_appnt where appnt_id=#{appntId};")
    ProposalAppnt selectAllAppnt(String appntId);

    /**
     * 通过投保人id修改投保人名字
     * @param appnt
     */
    @Update("update proposal_appnt set name=#{name} where appnt_id=#{proposalId};")
    void updateById(ProposalAppnt appnt);
}
